﻿@page "/_Admin/DicDef/Edit"
@using nERP.ViewModel._Admin.DicDefVMs
@using nERP.Model._Admin
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
    <Row ItemsPerRow="ItemsPerRow.One" RowType="RowType.Normal">
        <BootstrapInput @bind-Value="@Model.Entity.DicName" />

        <Table TItem="DicField"
               IsPagination="false"
               IsStriped="true" IsBordered="true" IsMultipleSelect="true" @bind-Items="@DicFieldDicDefList1"
               ShowToolbar="true" ShowExtendButtons="true" ShowSkeleton="true" EditMode="EditMode.InCell" ShowToastAfterSaveOrDeleteModel="false">
            <TableColumns>
                <TableColumn @bind-Field="@context.DicFieldName" Text="@WtmBlazor.Localizer["Page.键"]" />
                <TableColumn @bind-Field="@context.DicFieldDes" Text="@WtmBlazor.Localizer["Page.值"]" />
                <TableColumn @bind-Field="@context.Order" Text="@WtmBlazor.Localizer["Page.排序"]" />
            </TableColumns>

        </Table>

    </Row>

    <div class="modal-footer table-modal-footer">
        <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" Icon="fas fa-check" Color="Color.Success" />
        <Button OnClick="OnClose" Icon="fas fa-arrow-right-from-bracket" Text="@WtmBlazor.Localizer["Sys.Close"]" Color="Color.Info" />
    </div>

</ValidateForm>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private DicDefVM Model = new DicDefVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {

        Model.Entity.DicField_DicDef = DicFieldDicDefList1.ToList();

        await PostsForm(vform, "/api/_Admin/DicDef/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllDicDefs = new List<SelectedItem>();
    private IEnumerable<DicField> DicFieldDicDefList1 { get; set; } = new List<DicField>();
    protected override async Task OnInitializedAsync()
    {


        AllDicDefs = await WtmBlazor.Api.CallItemsApi("/api/_Admin/DicField/GetDicDefs");
        AllDicDefs.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<DicDefVM>($"/api/_Admin/DicDef/{id}");
            Model = rv.Data;
        }
        DicFieldDicDefList1 = Model.Entity.DicField_DicDef;

        await base.OnInitializedAsync();
    }
}
